<template>
  <div>
    <div class="pwd">
      <div class="title3">修改密码表单</div>
      <el-form :model="forData" label-width="100px" class="demo-ruleForm">
        <el-form-item label="原始密码">
          <el-input
            v-model="forData.oldPassword"
            class="inputpwdtitle"
          ></el-input>
        </el-form-item>
        <el-form-item label="新密码">
          <el-input
            v-model="forData.newPassword"
            class="inputpwd2"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item class="button">
          <el-button class="btn" type="primary" @click="submitBtn"
            >确认修改</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { getUpdateUserApi } from "@/api/user.js";
import { ElMessage } from "element-plus";
import { useRouter } from "vue-router";
import pinia from "@/store";
import useCounter from "@/store/counter";
const counterStore = useCounter(pinia);
import { ref, reactive } from "vue";
const router = useRouter();
const forData = reactive({
  oldPassword: "",
  newPassword: "",
});

const submitBtn = async () => {
  try {
    const params = {
      id: counterStore.id,
      uuid: counterStore.uuid,
      oldPass: forData.oldPassword,
      newPass: forData.newPassword,
    };
    const res = await getUpdateUserApi(params);
    console.log(res);
    if (res.message === "success") {
      router.push("/login");
      ElMessage({
        message: "修改密码成功！请重新登录！",
        type: "success",
      });
    } else {
      ElMessage({
        message: "原密码输入错误！请重试！",
        type: "error",
      });
    }
  } catch (error) {
    console.log(error);
  }
};
</script>

<style lang="scss" scoped>
.pwd {
  width: 100%;
  padding: 30px;
}
.demo-ruleForm {
  width: 400px;
  height: 200px;
  background: white;
  padding: 50px;
  margin-left: 300px;
}
.inputpwd {
  width: 300px;
}

.inputpwd2 {
  width: 300px;
}

.title3 {
  width: 94%;
  height: 60px;
  color: #858585;
  font-weight: 600;
  text-align: center;
  line-height: 60px;
  font-size: 30px;
  margin-top: 20px;
}
.button {
  margin-left: 100px;
}
</style>
